package com.beiye.drivertransport.curriulum;

import android.content.Context;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.alibaba.fastjson.JSON;
import com.android.frame.adapter.CommonAdapter;
import com.android.frame.adapter.ViewHolder;
import com.beiye.drivertransport.R;
import com.beiye.drivertransport.activity.TwoBaseAty;
import com.beiye.drivertransport.bean.LoginUserBean;
import com.beiye.drivertransport.bean.SpecifiedLearningCourseBean;
import com.beiye.drivertransport.bean.SpecifiedPhotoBean;
import com.beiye.drivertransport.config.AppInterfaceConfig;
import com.beiye.drivertransport.http.Login;
import com.beiye.drivertransport.utils.TiShiDialog;
import com.beiye.drivertransport.utils.UserManger;
import com.beiye.drivertransport.utils.Utils;
import com.beiye.drivertransport.view.MyListView;
import com.githang.statusbar.StatusBarCompat;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.StringCallback;
import com.squareup.picasso.Picasso;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;


import butterknife.OnClick;
import okhttp3.Call;
import okhttp3.Response;

public class SubSpecifiedLearnRecordActivity extends TwoBaseAty {

    ImageView img_safeback;

    TextView tv_title;

    TextView tv_setChLength;

    TextView tv_actualChLength;

    MyListView lv_course;

    View empty_view;
    private SpecifiedLearningAdapter specifiedLearningAdapter;
    ArrayList<SpecifiedLearningCourseBean.RowsBean> courseList = new ArrayList<>();
    ArrayList<Integer> LengthList = new ArrayList<>();

    private int rtype;

    @Override
    public int getLayoutId() {
        return R.layout.activity_sub_specified_learn_record;
    }


    public void onClick(View view) {
        if (view.getId() == R.id.img_safeback) {
            finish();
        }
    }

    @Override
    public void initData() {
        img_safeback = (ImageView) findViewById(R.id.img_safeback);
        tv_title = (TextView) findViewById(R.id.tv_title);
        tv_setChLength = (TextView) findViewById(R.id.tv_setChLength);
        tv_actualChLength = (TextView) findViewById(R.id.tv_actualChLength);
        lv_course = (MyListView) findViewById(R.id.lv_course);
        empty_view = (View) findViewById(R.id.empty_view);
        StatusBarCompat.setStatusBarColor(this, Color.parseColor("#1F80C4"));
        Bundle bundle = getIntent().getExtras();
        String orgId = bundle.getString("orgId");
        int sn = bundle.getInt("sn");
        int actualChLength = bundle.getInt("actualChLength");
        int setChLength = bundle.getInt("setChLength");
        int chNo = bundle.getInt("chNo");
        int checkMark = bundle.getInt("checkMark");
        int finishMark = bundle.getInt("finishMark");
        String chName = bundle.getString("chName");
        int qpSn = bundle.getInt("qpSn");
        rtype=bundle.getInt("rtype");
        SharedPreferences sp1 = getSharedPreferences("SubSpecifiedLearnRecordActivity",
                Context.MODE_PRIVATE);
        SharedPreferences.Editor edit1 = sp1.edit();

        edit1.putInt("sn", sn);
        edit1.putInt("checkMark", checkMark);
        edit1.putInt("finishMark", finishMark);
        edit1.putInt("setChLength", setChLength);
        edit1.putString("orgId", orgId);
        edit1.putInt("qpSn", qpSn);

        edit1.commit();

        if (chName.equals("")) {
            tv_title.setText("");
        } else {
            tv_title.setText(chName);
        }
        if (chNo == 0) {
            tv_setChLength.setText("0");
        } else {
            tv_setChLength.setText(chNo + "");
        }

    }

    @Override
    public void requestData() {
        LoginUserBean userInfo = UserManger.getUserInfo();
        LoginUserBean.DataBean data = userInfo.getData();
        if (data == null) {
            return;
        }
        String userId = data.getUserId();
        SharedPreferences sp1 = getSharedPreferences("SubSpecifiedLearnRecordActivity",
                Context.MODE_PRIVATE);
        int sn = sp1.getInt("sn", 0);
        showLoadingDialog("");
        new Login().getSpecifiedLearningcourser(userId, sn, rtype+"", this, 1);

    }

    @Override
    public void onSuccess(String result, Call call, Response response, int what) {
        if (what == 1) {
            dismissLoadingDialog();
            SpecifiedLearningCourseBean learnCourseBean = JSON.parseObject(result, SpecifiedLearningCourseBean.class);
            List<SpecifiedLearningCourseBean.RowsBean> rows = learnCourseBean.getRows();
            if (rows.size() == 0) {
                lv_course.setEmptyView(empty_view);
                tv_actualChLength.setText("0%");
                return;
            }
            courseList.clear();
            courseList.addAll(rows);
            specifiedLearningAdapter = new SpecifiedLearningAdapter(SubSpecifiedLearnRecordActivity.this, courseList, R.layout.specified_course_item);
            lv_course.setAdapter(specifiedLearningAdapter);

            LengthList.clear();
            for (int i = 0; i < courseList.size(); i++) {
                if (courseList.get(i).getMark() == 1) {
                    LengthList.add(courseList.get(i).getCourseLength());
                }

            }
            int length = 0;
            for (Integer num : LengthList) {
                length += num;
            }
            SharedPreferences sp = getSharedPreferences("SubSpecifiedLearnRecordActivity",
                    Context.MODE_PRIVATE);
            int setChLength = sp.getInt("setChLength", 0);
            int finishMark = sp.getInt("finishMark", 0);
            int qpSn = sp.getInt("qpSn", 0);
            if (finishMark == 0) {
                if (length == 0 || setChLength == 0) {
                    tv_actualChLength.setText("0%");
                } else {
                    float studyper = (float) length / (float) setChLength;
                    if (studyper < 1) {
                        int studyper1 = (int) (studyper * 100);
                        //  String ss = String.format("%1.2f", studyper1);
                        tv_actualChLength.setText(studyper1 + "%");
                        tv_actualChLength.setTextColor(SubSpecifiedLearnRecordActivity.this.getResources().getColor(R.color.bixue_red));
                    } else {
                        if (qpSn == 0)//未考试
                        {
                            tv_actualChLength.setText(99 + "%");
                            tv_actualChLength.setTextColor(SubSpecifiedLearnRecordActivity.this.getResources().getColor(R.color.bixue_red));
                        } else {//要考试
                            tv_actualChLength.setText(100 + "%");
                            tv_actualChLength.setTextColor(SubSpecifiedLearnRecordActivity.this.getResources().getColor(R.color.holetotal_yellow));
                        }
                    }

                }
            } else {
                tv_actualChLength.setText(100 + "%");
                tv_actualChLength.setTextColor(SubSpecifiedLearnRecordActivity.this.getResources().getColor(R.color.holetotal_gray));
            }

        }


        super.onSuccess(result, call, response, what);
    }

    public class SpecifiedLearningAdapter extends CommonAdapter<SpecifiedLearningCourseBean.RowsBean> {
        private Context context;
        private List<SpecifiedLearningCourseBean.RowsBean> mList;
        private PopupWindow mPopWindow;


        public SpecifiedLearningAdapter(Context context, List<SpecifiedLearningCourseBean.RowsBean> mList, int itemLayoutId) {
            super(context, mList, itemLayoutId);
            this.context = context;
            this.mList = mList;
        }


        private void initphotodata(final int sn) {
            if (sn == 0) {
                return;
            }
            OkGo.get(AppInterfaceConfig.BASE_URL + "course/userTcPhoto/findTc/" + sn)     // 请求方式和请求url
                    .tag(this)                       // 请求的 tag, 主要用于取消对应的请求
                    .execute(new StringCallback() {
                        @Override
                        public void onSuccess(String result, Call call, Response response) {
                            SpecifiedPhotoBean specifiedPhotoBean = JSON.parseObject(result, SpecifiedPhotoBean.class);
                            List<SpecifiedPhotoBean.RowsBean> rows = specifiedPhotoBean.getRows();

                            if (rows.size() == 0) {
                                SharedPreferences sp = getSharedPreferences("SubSpecifiedLearnRecordActivity",
                                        Context.MODE_PRIVATE);
                                SharedPreferences.Editor edit = sp.edit();
                                edit.putString("photourl" + sn, "");
                                edit.commit();
                                return;
                            }
                            if (rows.size() == 1) {
                                String url = specifiedPhotoBean.getRows().get(0).getUrl();
                                if (url == null) {
                                    SharedPreferences sp = getSharedPreferences("SubSpecifiedLearnRecordActivity",
                                            Context.MODE_PRIVATE);
                                    SharedPreferences.Editor edit = sp.edit();
                                    edit.putString("photourl" + sn, "");
                                    edit.commit();

                                } else {
                                    SharedPreferences sp = getSharedPreferences("SubSpecifiedLearnRecordActivity",
                                            Context.MODE_PRIVATE);
                                    SharedPreferences.Editor edit = sp.edit();
                                    edit.putString("photourl" + sn, url);
                                    edit.commit();
                                }
                            } else if (rows.size() == 2) {
                                String url = specifiedPhotoBean.getRows().get(0).getUrl();
                                String url1 = specifiedPhotoBean.getRows().get(1).getUrl();
                                if (url == null) {
                                    SharedPreferences sp = getSharedPreferences("SubSpecifiedLearnRecordActivity",
                                            Context.MODE_PRIVATE);
                                    SharedPreferences.Editor edit = sp.edit();
                                    edit.putString("photourl" + sn, "");
                                    edit.commit();
                                } else {
                                    SharedPreferences sp = getSharedPreferences("SubSpecifiedLearnRecordActivity",
                                            Context.MODE_PRIVATE);
                                    SharedPreferences.Editor edit = sp.edit();
                                    edit.putString("photourl" + sn, url);
                                    edit.commit();
                                    if (url1 == null) {
                                        SharedPreferences sp1 = getSharedPreferences("SubSpecifiedLearnRecordActivity",
                                                Context.MODE_PRIVATE);
                                        SharedPreferences.Editor edit1 = sp1.edit();
                                        edit1.putString("photourl1" + sn, "");
                                        edit1.commit();
                                    } else {
                                        SharedPreferences sp1 = getSharedPreferences("SubSpecifiedLearnRecordActivity",
                                                Context.MODE_PRIVATE);
                                        SharedPreferences.Editor edit1 = sp1.edit();
                                        edit1.putString("photourl1" + sn, url1);
                                        edit1.commit();
                                    }
                                }

                            } else if (rows.size() == 3) {
                                String url = specifiedPhotoBean.getRows().get(0).getUrl();
                                String url1 = specifiedPhotoBean.getRows().get(1).getUrl();
                                String url2 = specifiedPhotoBean.getRows().get(2).getUrl();
                                if (url == null) {
                                    SharedPreferences sp = getSharedPreferences("SubSpecifiedLearnRecordActivity",
                                            Context.MODE_PRIVATE);
                                    SharedPreferences.Editor edit = sp.edit();
                                    edit.putString("photourl" + sn, "");
                                    edit.commit();
                                } else {
                                    SharedPreferences sp = getSharedPreferences("SubSpecifiedLearnRecordActivity",
                                            Context.MODE_PRIVATE);
                                    SharedPreferences.Editor edit = sp.edit();
                                    edit.putString("photourl" + sn, url);
                                    edit.commit();
                                    if (url1 == null) {
                                        SharedPreferences sp1 = getSharedPreferences("SubSpecifiedLearnRecordActivity",
                                                Context.MODE_PRIVATE);
                                        SharedPreferences.Editor edit1 = sp1.edit();
                                        edit1.putString("photourl1" + sn, "");
                                        edit1.commit();
                                    } else {
                                        SharedPreferences sp1 = getSharedPreferences("SubSpecifiedLearnRecordActivity",
                                                Context.MODE_PRIVATE);
                                        SharedPreferences.Editor edit1 = sp1.edit();
                                        edit1.putString("photourl1" + sn, url1);
                                        edit1.commit();
                                        if (url2 == null) {
                                            SharedPreferences sp2 = getSharedPreferences("SubSpecifiedLearnRecordActivity",
                                                    Context.MODE_PRIVATE);
                                            SharedPreferences.Editor edit2 = sp2.edit();
                                            edit2.putString("photourl2" + sn, "");
                                            edit2.commit();
                                        } else {
                                            SharedPreferences sp2 = getSharedPreferences("SubSpecifiedLearnRecordActivity",
                                                    Context.MODE_PRIVATE);
                                            SharedPreferences.Editor edit2 = sp2.edit();
                                            edit2.putString("photourl2" + sn, url2);
                                            edit2.commit();
                                        }

                                    }
                                }

                            } else if (rows.size() == 4) {
                                String url = specifiedPhotoBean.getRows().get(0).getUrl();
                                String url1 = specifiedPhotoBean.getRows().get(1).getUrl();
                                String url2 = specifiedPhotoBean.getRows().get(2).getUrl();
                                String url3 = specifiedPhotoBean.getRows().get(3).getUrl();
                                if (url == null) {
                                    SharedPreferences sp = getSharedPreferences("SubSpecifiedLearnRecordActivity",
                                            Context.MODE_PRIVATE);
                                    SharedPreferences.Editor edit = sp.edit();
                                    edit.putString("photourl" + sn, "");
                                    edit.commit();
                                } else {
                                    SharedPreferences sp = getSharedPreferences("SubSpecifiedLearnRecordActivity",
                                            Context.MODE_PRIVATE);
                                    SharedPreferences.Editor edit = sp.edit();
                                    edit.putString("photourl" + sn, url);
                                    edit.commit();
                                    if (url1 == null) {
                                        SharedPreferences sp1 = getSharedPreferences("SubSpecifiedLearnRecordActivity",
                                                Context.MODE_PRIVATE);
                                        SharedPreferences.Editor edit1 = sp1.edit();
                                        edit1.putString("photourl1" + sn, "");
                                        edit1.commit();
                                    } else {
                                        SharedPreferences sp1 = getSharedPreferences("SubSpecifiedLearnRecordActivity",
                                                Context.MODE_PRIVATE);
                                        SharedPreferences.Editor edit1 = sp1.edit();
                                        edit1.putString("photourl1" + sn, url1);
                                        edit1.commit();
                                        if (url2 == null) {
                                            SharedPreferences sp2 = getSharedPreferences("SubSpecifiedLearnRecordActivity",
                                                    Context.MODE_PRIVATE);
                                            SharedPreferences.Editor edit2 = sp2.edit();
                                            edit2.putString("photourl2" + sn, "");
                                            edit2.commit();
                                        } else {
                                            SharedPreferences sp2 = getSharedPreferences("SubSpecifiedLearnRecordActivity",
                                                    Context.MODE_PRIVATE);
                                            SharedPreferences.Editor edit2 = sp2.edit();
                                            edit2.putString("photourl2" + sn, url2);
                                            edit2.commit();

                                            if (url3 == null) {
                                                SharedPreferences sp3 = getSharedPreferences("SubSpecifiedLearnRecordActivity",
                                                        Context.MODE_PRIVATE);
                                                SharedPreferences.Editor edit3 = sp3.edit();
                                                edit3.putString("photourl3" + sn, "");
                                                edit3.commit();
                                            } else {
                                                SharedPreferences sp3 = getSharedPreferences("SubSpecifiedLearnRecordActivity",
                                                        Context.MODE_PRIVATE);
                                                SharedPreferences.Editor edit3 = sp3.edit();
                                                edit3.putString("photourl3" + sn, url3);
                                                edit3.commit();
                                                ;
                                            }


                                        }

                                    }
                                }

                            } else if (rows.size() >= 5) {
                                String url = specifiedPhotoBean.getRows().get(0).getUrl();
                                String url1 = specifiedPhotoBean.getRows().get(1).getUrl();
                                String url2 = specifiedPhotoBean.getRows().get(2).getUrl();
                                String url3 = specifiedPhotoBean.getRows().get(3).getUrl();
                                String url4 = specifiedPhotoBean.getRows().get(4).getUrl();
                                if (url == null) {
                                    SharedPreferences sp = getSharedPreferences("SubSpecifiedLearnRecordActivity",
                                            Context.MODE_PRIVATE);
                                    SharedPreferences.Editor edit = sp.edit();
                                    edit.putString("photourl" + sn, "");
                                    edit.commit();
                                } else {
                                    SharedPreferences sp = getSharedPreferences("SubSpecifiedLearnRecordActivity",
                                            Context.MODE_PRIVATE);
                                    SharedPreferences.Editor edit = sp.edit();
                                    edit.putString("photourl" + sn, url);
                                    edit.commit();
                                    if (url1 == null) {
                                        SharedPreferences sp1 = getSharedPreferences("SubSpecifiedLearnRecordActivity",
                                                Context.MODE_PRIVATE);
                                        SharedPreferences.Editor edit1 = sp1.edit();
                                        edit1.putString("photourl1" + sn, "");
                                        edit1.commit();
                                    } else {
                                        SharedPreferences sp1 = getSharedPreferences("SubSpecifiedLearnRecordActivity",
                                                Context.MODE_PRIVATE);
                                        SharedPreferences.Editor edit1 = sp1.edit();
                                        edit1.putString("photourl1" + sn, url1);
                                        edit1.commit();
                                        if (url2 == null) {
                                            SharedPreferences sp2 = getSharedPreferences("SubSpecifiedLearnRecordActivity",
                                                    Context.MODE_PRIVATE);
                                            SharedPreferences.Editor edit2 = sp2.edit();
                                            edit2.putString("photourl2" + sn, "");
                                            edit2.commit();
                                        } else {
                                            SharedPreferences sp2 = getSharedPreferences("SubSpecifiedLearnRecordActivity",
                                                    Context.MODE_PRIVATE);
                                            SharedPreferences.Editor edit2 = sp2.edit();
                                            edit2.putString("photourl2" + sn, url2);
                                            edit2.commit();

                                            if (url3 == null) {
                                                SharedPreferences sp3 = getSharedPreferences("SubSpecifiedLearnRecordActivity",
                                                        Context.MODE_PRIVATE);
                                                SharedPreferences.Editor edit3 = sp3.edit();
                                                edit3.putString("photourl3" + sn, "");
                                                edit3.commit();
                                            } else {
                                                SharedPreferences sp3 = getSharedPreferences("SubSpecifiedLearnRecordActivity",
                                                        Context.MODE_PRIVATE);
                                                SharedPreferences.Editor edit3 = sp3.edit();
                                                edit3.putString("photourl3" + sn, url3);
                                                edit3.commit();
                                                ;
                                                if (url4 == null) {
                                                    SharedPreferences sp4 = getSharedPreferences("SubSpecifiedLearnRecordActivity",
                                                            Context.MODE_PRIVATE);
                                                    SharedPreferences.Editor edit4 = sp4.edit();
                                                    edit4.putString("photourl4" + sn, "");
                                                    edit4.commit();
                                                } else {
                                                    SharedPreferences sp4 = getSharedPreferences("SubSpecifiedLearnRecordActivity",
                                                            Context.MODE_PRIVATE);
                                                    SharedPreferences.Editor edit4 = sp4.edit();
                                                    edit4.putString("photourl4" + sn, url4);
                                                    edit4.commit();
                                                }
                                            }


                                        }

                                    }
                                }

                            }
                        }

                        @Override
                        public void onError(Call call, Response response, Exception e) {
                            super.onError(call, response, e);
                            //  showToast("网络连接错误");
                        }
                    });

        }


        @Override
        public void convert(ViewHolder holder, final SpecifiedLearningCourseBean.RowsBean item, final int positon) {

            TextView tv_ttName = holder.getView(R.id.tv_ttName);
            TextView tv_courseLength = holder.getView(R.id.tv_courseLength);
            TextView tv_creationDate = holder.getView(R.id.tv_creationDate);
            TextView tv_courseName = holder.getView(R.id.tv_courseName);
            TextView tv_learnyesorno = holder.getView(R.id.tv_parent4);
            TextView tv_buxue = holder.getView(R.id.tv_parent8);
            TextView tv_supermarket = holder.getView(R.id.tv_parent5);
            TextView tv_learnphoto = holder.getView(R.id.tv_learnphoto);//学习照片
            final TextView tv_learn = holder.getView(R.id.tv_learn);
            int otcSn = mList.get(positon).getOtcSn();
            long creationDate = mList.get(positon).getCreationDate();
            int mark = mList.get(positon).getMark();
            int muMark = mList.get(positon).getMuMark();
            String ttName = mList.get(positon).getTtName();
            String courseName = mList.get(positon).getCourseName();
            int courseLength = mList.get(positon).getCourseLength();
            int readLength = mList.get(positon).getReadLength();
            final int sn = mList.get(positon).getSn();
            if (sn == 0) {
                initphotodata(0);
            } else {
                initphotodata(sn);
            }
            if (ttName == null) {
                tv_ttName.setText("");
            } else {
                tv_ttName.setText(ttName);
            }
            if (courseName == null) {
                tv_courseName.setText("");
            } else {
                tv_courseName.setText(courseName);
            }
            if (courseLength == 0) {
                tv_courseLength.setText("分钟");
            } else {
                tv_courseLength.setText(courseLength + "分钟");
            }
//            if(mark==1)
//            {
//                tv_learnyesorno.setVisibility(View.VISIBLE);
//                tv_learnyesorno.setText("已学习");
//                tv_learnyesorno.setBackgroundResource(R.drawable.shape_specified_yes);
//            }else if(mark==0){
//                tv_learnyesorno.setVisibility(View.VISIBLE);
//                tv_learnyesorno.setText("未学完");
//                tv_learnyesorno.setBackgroundResource(R.drawable.shape_specified_nored);
//            }

            SharedPreferences sp1 = getSharedPreferences("SubSpecifiedLearnRecordActivity",
                    Context.MODE_PRIVATE);
            int checkMark = sp1.getInt("checkMark", 0);
            int finishMark = sp1.getInt("finishMark", 0);
            if (finishMark == 0) {
                if (mark == 1) {
                    tv_learnyesorno.setVisibility(View.VISIBLE);
                    tv_learnyesorno.setText("已学习");
                    tv_learnyesorno.setBackgroundResource(R.drawable.shape_specified_yes);
                    // tv_learn.setText("重新学习");
                    tv_learn.setVisibility(View.INVISIBLE);
                    tv_learnphoto.setVisibility(View.VISIBLE);

                } else if (mark == 0) {
                    if (readLength > 0) {
                        tv_learnyesorno.setVisibility(View.VISIBLE);
                        tv_learnyesorno.setText("未学完");
                        tv_learnyesorno.setBackgroundResource(R.drawable.shape_specified_noorange);
                        // tv_learn.setText("继续学习");
                        tv_learn.setVisibility(View.INVISIBLE);
                        tv_learnphoto.setVisibility(View.VISIBLE);


                    } else {
                        tv_learnyesorno.setVisibility(View.VISIBLE);
                        tv_learnyesorno.setText("未学习");
                        tv_learnyesorno.setBackgroundResource(R.drawable.shape_specified_nored);
                        //  tv_learn.setText("开始学习");
                        tv_learn.setVisibility(View.INVISIBLE);
                        tv_learnphoto.setVisibility(View.GONE);
                    }

                }

            } else {
                if (checkMark == 0) {

                    if (mark == 1) {
                        tv_learnyesorno.setVisibility(View.VISIBLE);
                        tv_learnyesorno.setText("已学习");
                        tv_learnyesorno.setBackgroundResource(R.drawable.shape_specified_yes);
                        //  tv_learn.setText("重新学习");
                        tv_learn.setVisibility(View.INVISIBLE);
                        tv_learnphoto.setVisibility(View.VISIBLE);


                    } else if (mark == 0) {
                        if (readLength > 0) {
                            tv_learnyesorno.setVisibility(View.VISIBLE);
                            tv_learnyesorno.setText("未学完");
                            tv_learnyesorno.setBackgroundResource(R.drawable.shape_specified_noorange);
                            //    tv_learn.setText("继续学习");
                            tv_learn.setVisibility(View.INVISIBLE);
                            tv_learnphoto.setVisibility(View.VISIBLE);

                        } else {
                            tv_learnyesorno.setVisibility(View.VISIBLE);
                            tv_learnyesorno.setText("未学习");
                            tv_learnyesorno.setBackgroundResource(R.drawable.shape_specified_nored);
                            //    tv_learn.setText("开始学习");
                            tv_learn.setVisibility(View.INVISIBLE);
                            tv_learnphoto.setVisibility(View.GONE);
                        }
                    }

                } else {
                    if (mark == 1) {
                        tv_learnyesorno.setVisibility(View.VISIBLE);
                        tv_learnyesorno.setText("已学习");
                        tv_learnyesorno.setBackgroundResource(R.drawable.shape_specified_yes);
                        //   tv_learn.setVisibility(View.INVISIBLE);
                        //    tv_learn.setText("重新学习");
                        tv_learn.setVisibility(View.INVISIBLE);
                        tv_learnphoto.setVisibility(View.VISIBLE);

                    } else if (mark == 0) {

                        if (readLength > 0) {
                            tv_learnyesorno.setVisibility(View.VISIBLE);
                            tv_learnyesorno.setText("未学完");
                            tv_learnyesorno.setBackgroundResource(R.drawable.shape_specified_noorange);
                            //      tv_learn.setVisibility(View.VISIBLE);
                            //      tv_learn.setText("继续学习");
                            tv_learn.setVisibility(View.INVISIBLE);
                            tv_learnphoto.setVisibility(View.VISIBLE);

                        } else {
                            tv_learnyesorno.setVisibility(View.VISIBLE);
                            tv_learnyesorno.setText("未学习");
                            tv_learnyesorno.setBackgroundResource(R.drawable.shape_specified_nored);
                            //     tv_learn.setVisibility(View.VISIBLE);
                            //     tv_learn.setText("开始学习");
                            tv_learn.setVisibility(View.INVISIBLE);
                            tv_learnphoto.setVisibility(View.GONE);
                        }

                    }
                }
            }

            if (muMark == 1) {
                tv_buxue.setVisibility(View.VISIBLE);

            } else {
                tv_buxue.setVisibility(View.GONE);
            }
            if (otcSn != 0 && otcSn > 0) {
                tv_supermarket.setVisibility(View.GONE);
            } else {
                tv_supermarket.setVisibility(View.VISIBLE);
            }
            tv_learnphoto.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (Utils.isFastClicker()) {
                        return;
                    }
                    SharedPreferences sp = getSharedPreferences("SubSpecifiedLearnRecordActivity",
                            Context.MODE_PRIVATE);
                    String photourl = sp.getString("photourl" + sn, "");
                    String photourl1 = sp.getString("photourl1" + sn, "");
                    String photourl2 = sp.getString("photourl2" + sn, "");
                    String photourl3 = sp.getString("photourl3" + sn, "");
                    String photourl4 = sp.getString("photourl4" + sn, "");
                    if (photourl.equals("")) {
                        TiShiDialog.Builder builder1 = new TiShiDialog.Builder(SubSpecifiedLearnRecordActivity.this);
                        builder1.setMessage("您在本课程没有学习照片。");
                        builder1.setTitle("提示:");
                        builder1.setPositiveButton("确定", new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int which) {
                                dialog.dismiss();
                                ;
                                //设置你的操作事项
                            }
                        });
                        builder1.create().show();
                    } else {
                        View contentView = LayoutInflater.from(SubSpecifiedLearnRecordActivity.this).inflate(R.layout.popwindow_showphoto_layout, null);
                        mPopWindow = new PopupWindow(contentView,
                                WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT, true);
                        mPopWindow.showAtLocation(tv_title, Gravity.CENTER, 0, 0);
                        TextView tv_dismiss = (TextView) contentView.findViewById(R.id.tv_dismiss);
                        tv_dismiss.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                mPopWindow.dismiss();
                            }
                        });
                        final ImageView img_photo1 = (ImageView) contentView.findViewById(R.id.img_photo1);
                        final ImageView img_photo2 = (ImageView) contentView.findViewById(R.id.img_photo2);
                        final ImageView img_photo3 = (ImageView) contentView.findViewById(R.id.img_photo3);
                        final ImageView img_photo4 = (ImageView) contentView.findViewById(R.id.img_photo4);
                        final ImageView img_photo5 = (ImageView) contentView.findViewById(R.id.img_photo5);
                        if (photourl.contains("aliyuncs.com")) {
                            Picasso.with(context).load(Uri.parse(photourl)).placeholder(R.mipmap.no_data).into(img_photo1);
                        } else {

                            Picasso.with(context).load(Uri.parse(AppInterfaceConfig.getRequestUrl(photourl))).placeholder(R.mipmap.no_data).into(img_photo1);
                        }
                        if (!photourl1.equals("")) {
                            if (photourl1.contains("aliyuncs.com")) {
                                Picasso.with(context).load(Uri.parse(photourl1)).placeholder(R.mipmap.no_data).into(img_photo2);
                            } else {

                                Picasso.with(context).load(Uri.parse(AppInterfaceConfig.getRequestUrl(photourl1))).placeholder(R.mipmap.no_data).into(img_photo2);
                            }
                        } else {
                            img_photo2.setImageResource(R.drawable.normalphoto);
                        }
                        if (!photourl2.equals("")) {
                            if (photourl2.contains("aliyuncs.com")) {
                                Picasso.with(context).load(Uri.parse(photourl2)).placeholder(R.mipmap.no_data).into(img_photo3);
                            } else {

                                Picasso.with(context).load(Uri.parse(AppInterfaceConfig.getRequestUrl(photourl2))).placeholder(R.mipmap.no_data).into(img_photo3);
                            }
                        } else {
                            img_photo3.setImageResource(R.drawable.normalphoto);
                        }
                        if (!photourl3.equals("")) {
                            if (photourl3.contains("aliyuncs.com")) {
                                Picasso.with(context).load(Uri.parse(photourl3)).placeholder(R.mipmap.no_data).into(img_photo4);
                            } else {

                                Picasso.with(context).load(Uri.parse(AppInterfaceConfig.getRequestUrl(photourl3))).placeholder(R.mipmap.no_data).into(img_photo4);
                            }
                        } else {
                            img_photo4.setImageResource(R.drawable.normalphoto);
                        }
                        if (!photourl4.equals("")) {
                            if (photourl4.contains("aliyuncs.com")) {
                                Picasso.with(context).load(Uri.parse(photourl4)).placeholder(R.mipmap.no_data).into(img_photo5);
                            } else {

                                Picasso.with(context).load(Uri.parse(AppInterfaceConfig.getRequestUrl(photourl4))).placeholder(R.mipmap.no_data).into(img_photo5);
                            }
                        } else {
                            img_photo5.setImageResource(R.drawable.normalphoto);
                        }
                    }
                }
            });

            if (creationDate > 0) {
                String begin = "";
                try {
                    //yyyy表示年MM表示月dd表示日
                    //yyyy-MM-dd是日期的格式，比如2015-12-12如果你要得到2015年12月12日就换成yyyy年MM月dd日
                    SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd");
                    //进行格式化
                    begin = sdf.format(creationDate);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                tv_creationDate.setVisibility(View.VISIBLE);
                tv_creationDate.setText("学习时间: " + begin);

            } else {
                tv_creationDate.setVisibility(View.GONE);
            }

        }


    }
}
